package fr.miam.android_playboy;

import java.io.FileNotFoundException;
import java.io.IOException;

import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.provider.MediaStore.Images;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.Gallery;
import android.widget.Gallery.LayoutParams;
import android.widget.ImageView;
import android.widget.Toast;

@SuppressWarnings("deprecation")
public class MainActivity extends Activity {

	private final static String[] PROJECTION = {Images.Media._ID};
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		Gallery g = (Gallery) findViewById(R.id.gallery);
	    
		g.setCallbackDuringFling(true);
		g.setOnItemClickListener(new OnItemClickListener()
	    {
	        public void onItemClick(AdapterView<?> parent, View view, int position, long id)
	        {   		
	        	Intent i = new Intent(MainActivity.this, PictureActivity.class);
	        	i.putExtra("imgId", id);
	        	startActivity(i);
	         }
    	});
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}
	
	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		Gallery g = (Gallery) findViewById(R.id.gallery);
		Cursor c = Images.Media.query(this.getContentResolver(), Images.Media.EXTERNAL_CONTENT_URI,PROJECTION);
	    g.setAdapter(new GalleryImgAdapter(this, c));
	}
	
}
